package br.inf.solutions.apresentacoes.ssp.view.composer;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.Component;

import br.com.vexillum.util.ReflectionUtils;
import br.com.vexillum.util.SpringFactory;
import br.inf.solutions.apresentacoes.ssp.control.ModelNameController;
import br.inf.solutions.apresentacoes.ssp.control.hierarchy.HierarchyStructTypeController;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructType;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.ModelName;

@SuppressWarnings("serial")
@org.springframework.stereotype.Component
@Scope("prototype")
public class ModelNameComposer extends BaseComposer<ModelName, ModelNameController> {

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		loadBinder();
	}
	
	@SuppressWarnings("unchecked")
	public List<HierarchyStructType> getHierarchyTypes(){
		HierarchyStructTypeController controller = SpringFactory.getController("hierarchyStructTypeController", HierarchyStructTypeController.class, null);
		return (List<HierarchyStructType>) controller.doAction("listAll").getList();
	}
	
	@Override
	protected String getUpdatePage() {
		return "/paginas/modelosnome/modalCadastrar.zul";
	}

	@Override
	protected String getDeactivationMessage() {
		return "Tem certeza que deseja desativar o modelo " + getEntity().getName() + " para o tipo " + getEntity().getType().getName() + "?";
	}

	@Override
	public ModelNameController getControl() {
		return SpringFactory.getController("modelNameController", ModelNameController.class, ReflectionUtils.prepareDataForPersistence(this));
	}

	@Override
	public ModelName getEntityObject() {
		return new ModelName();
	}
	
}
